'''
''' This is the Event handler for Save Button. When the user clicks on the save button, The example saves the primary key
''' in a temporary ID variable, allowing you to add custom code that uses this variable.
'''
Public Sub ${Button Control}_Click(ByVal sender As Object, ByVal args As EventArgs)
' Please remove the above code: SaveButton_Click_Base(sender, args) for this customization to run successfully.
' Set shouldRedirect as true
Dim shouldRedirect As Boolean = true
Try
' Start Transaction and save data
DbUtils.StartTransaction()
Me.SaveData()
Me.CommitTransaction(sender)
' Get record control.
Dim rec As ${Table Name}Record = Me.${Record Control Class}.GetRecord
' Retrieving integer primary key and do more code customization like passing the retrieved value to another page, stored procedure and so on.
Dim tempId As String = rec.${Primary Key Field}.ToString()
' For example, redirect to another page by passing the saved record's ID
Me.Page.Response.Redirect("../OtherPages/SomeOtherPage.aspx&ID=" + tempId )
Catch ex As Exception
shouldRedirect = false
Me.RollBackTransaction(sender)
Me.ErrorOnPage = True
' If there is an Exception then display an alert message
BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
Finally
DbUtils.EndTransaction()
End Try
' If shouldredirect then save controls to session and redirect back
If shouldRedirect Then
Me.ShouldSaveControlsToSession = true
Me.RedirectBack()
End If
End Sub
|